import openai
openai.api_key = "EMPTY" # Not support yet
# openai.api_base = "http://localhost:8000/v1"
openai.api_base = "http://10.25.10.154:7860/"

model = "vicuna-13b-v1.3"
prompt = "Once upon a time"

# create a completion
completion = openai.Completion.create(model=model, prompt=prompt, max_tokens=64)
# print the completion
print(prompt + completion.choices[0].text)

# create a chat completion
completion = openai.ChatCompletion.create(
  model=model,
  messages=[{"role": "user", "content": "Hello! What is your name?"}]
)
# print the completion
print(completion.choices[0].message.content)
import openai
openai.api_key = "EMPTY"
openai.api_base = "http://10.25.10.154:7860"
model = "chatglm2-6b"
# model = "vicuna-13b-v1.3"
prompt = "Once upon a time"

# 创建一个文本生成完成
completion = openai.Completion.create(model=model, prompt=prompt, max_tokens=64)
# 打印生成的文本
print(prompt + completion.choices[0].text)

# 创建一个聊天完成
completion = openai.ChatCompletion.create(
  model=model,
  messages=[
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "Hello! What is your name?"}
  ]
)
# 打印生成的回复
print(completion.choices[0].message.content)
##python读取WORD
##将WORD的文本全部提出
##拼接成传入到LLM的输入
##跟参数一起传入进LLM
##对模型输出结果的内容与格式进行判定
##出现问题重新传入进模型直至得到合格的输出
##对输出的JSON进行解析
##最终得到三元组
##构建进graph内
##对已知的graph进行更新
##再次请求LLM时增加graph进行指导
#
# import os
# import openai
#
# os.environ['OPENAI_API_KEY'] = "your-OpenAI-API-key"
# openai.api_key = os.environ['OPENAI_API_KEY']
#
# question = "When did apple announced the Vision Pro?"
# completion = openai.ChatCompletion.create(model="gpt-3.5-turbo",
#                                           temperature=0,
#                                           messages=[{"role": "user",
#                                                      "content": question}])
# print(completion["choices"][0]["message"]["content"])
#
# from langchain.llms import OpenAI
# from langchain.indexes import GraphIndexCreator
# from langchain.chains import GraphQAChain
# from langchain.prompts import PromptTemplate
#
# text = "Apple announced the Vision Pro in 2023."
#
# index_creator = GraphIndexCreator(llm=OpenAI(temperature=0))
# graph = index_creator.from_text(text)
# graph.get_triples()
#
# import networkx as nx
# import matplotlib.pyplot as plt
#
# # Create graph
# G = nx.DiGraph()
# G.add_edges_from((source, target, {'relation': relation}) for source, relation, target in graph.get_triples())
#
# # Plot the graph
# plt.figure(figsize=(8,5), dpi=300)
# pos = nx.spring_layout(G, k=3, seed=0)
#
# nx.draw_networkx_nodes(G, pos, node_size=2000)
# nx.draw_networkx_edges(G, pos, edge_color='gray')
# nx.draw_networkx_labels(G, pos, font_size=12)
# edge_labels = nx.get_edge_attributes(G, 'relation')
# nx.draw_networkx_edge_labels(G, pos, edge_labels=edge_labels, font_size=10)
#
# # Display the plot
# plt.axis('off')
# plt.show()
#
#
# chain = GraphQAChain.from_llm(OpenAI(temperature=0), graph=graph, verbose=True)
# chain.run(question)
#
#
#
#
#
#
# from langchain.graphs.networkx_graph import KnowledgeTriple
#
# # Knowledge graph
# kg = [
#     ('Apple', 'is', 'Company'),
#     ('Apple', 'created', 'iMac'),
#     ('Apple', 'created', 'iPhone'),
#     ('Apple', 'created', 'Apple Watch'),
#     ('Apple', 'created', 'Vision Pro'),
#
#     ('Apple', 'developed', 'macOS'),
#     ('Apple', 'developed', 'iOS'),
#     ('Apple', 'developed', 'watchOS'),
#
#     ('Apple', 'is located in', 'USA'),
#     ('Steve Jobs', 'co-founded', 'Apple'),
#     ('Steve Wozniak', 'co-founded', 'Apple'),
#     ('Tim Cook', 'is the CEO of', 'Apple'),
#
#     ('iOS', 'runs on', 'iPhone'),
#     ('macOS', 'runs on', 'iMac'),
#     ('watchOS', 'runs on', 'Apple Watch'),
#
#     ('Apple', 'was founded in', '1976'),
#     ('Apple', 'owns', 'App Store'),
#     ('App Store', 'sells', 'iOS apps'),
#
#     ('iPhone', 'announced in', '2007'),
#     ('iMac', 'announced in', '1998'),
#     ('Apple Watch', 'announced in', '2014'),
#     ('Vision Pro', 'announced in', '2023'),
# ]
#
# graph = index_creator.from_text('')
# for (node1, relation, node2) in kg:
#     graph.add_triple(KnowledgeTriple(node1, relation, node2))
#
# # Create directed graph
# G = nx.DiGraph()
# for node1, relation, node2 in kg:
#     G.add_edge(node1, node2, label=relation)
#
# # Plot the graph
# plt.figure(figsize=(25, 25), dpi=300)
# pos = nx.spring_layout(G, k=2, iterations=50, seed=0)
#
# nx.draw_networkx_nodes(G, pos, node_size=5000)
# nx.draw_networkx_edges(G, pos, edge_color='gray', edgelist=G.edges(), width=2)
# nx.draw_networkx_labels(G, pos, font_size=12)
# edge_labels = nx.get_edge_attributes(G, 'label')
# nx.draw_networkx_edge_labels(G, pos, edge_labels=edge_labels, font_size=12)
#
# # Display the plot
# plt.axis('off')
# plt.show()
#
# chain = GraphQAChain.from_llm(OpenAI(temperature=0), graph=graph, verbose=True)
# chain.run(question)